home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ex / checkdisk.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  2KB  |  85 lines

  1. /* checkdisk.c */
  2.  
  3. #include "devices/trackdisk.h"
  4.  
  5. #define BLOCKSIZE TD_SECTOR
  6. #define TRACKSIZE TD_SECTOR * NUMSECS
  7. #define MEMF_CHIP (1L<<1)
  8.  
  9. unsigned char *diskbuffer;
  10. long td_open_error = -1;
  11.  
  12. struct MsgPort *diskport;
  13. struct IOExtTD *diskreq;
  14.  
  15. extern struct MsgPort *CreatePort();
  16. extern struct IORequest *CreateExtIO();
  17.  
  18. void MotorOnOff(onoff)    /* TURN DISK MOTOR ON/OFF */
  19. long onoff;
  20. {
  21.  diskreq->iotd_Req.io_Length = onoff;
  22.  diskreq->iotd_Req.io_Command = TD_MOTOR;
  23.  DoIO(diskreq);
  24. }
  25.  
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. {
  31. long unit, offset;
  32.  
  33. if (argc>1)
  34. {
  35.  unit = atoi(argv[1]);
  36.  if( unit < 0 || unit > 3) exit(0);
  37. }
  38. else
  39.  unit = 1;
  40.  
  41. if((diskbuffer = AllocMem(TRACKSIZE,MEMF_CHIP))==0) cleanup();
  42.     
  43. if((diskport = CreatePort(0,0)) == 0) cleanup();
  44. /* make an io request block for communicating with the disk */
  45. if((diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD)))== 0)
  46.     cleanup();    
  47.  
  48. if(td_open_error = OpenDevice(TD_NAME,unit,diskreq,0)) cleanup();
  49.  
  50. MotorOnOff(1); /* Motor On */
  51.  
  52. for(offset=0;offset<TRACKSIZE*NUMCYLS*NUMHEADS;offset+=TRACKSIZE)    
  53. {
  54.    diskreq->iotd_Req.io_Flags = 0;      
  55.    diskreq->iotd_Req.io_Length = TRACKSIZE;      
  56.    diskreq->iotd_Req.io_Data = (APTR)diskbuffer;    
  57.    diskreq->iotd_Req.io_Offset = offset; /* type long */
  58.    diskreq->iotd_Req.io_Command = ETD_READ;
  59.         /* check that disk not changed before reading */
  60.    diskreq->iotd_Count = 0xFFFFFFFF;
  61.    diskreq->iotd_SecLabel = 0;        
  62.     
  63.    DoIO(diskreq);
  64.  
  65.    if(diskreq->iotd_Req.io_Error != 0) 
  66.    printf("\nError %ld at Cylinder %ld, Head %ld.",
  67.     diskreq->iotd_Req.io_Error,
  68.         offset/(NUMHEADS*TRACKSIZE),
  69.         offset/(NUMCYLS*TRACKSIZE) );
  70. }
  71. MotorOnOff(0);
  72.  
  73. cleanup();
  74. }    /* end of main */
  75.  
  76. cleanup()
  77. {
  78. if(diskbuffer) FreeMem(diskbuffer,BLOCKSIZE);
  79. if(!td_open_error) CloseDevice(diskreq);
  80. if(diskreq) DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  81. if(diskport) DeletePort(diskport);
  82. exit(0);
  83. }
  84.  
  85.